module InvitationRequestsAcceptanceHelper
	protected
	def get_invitation_request
		id = params[:id]
		if id.blank?
			flash[:error] = "An invitation request id must be provided"
			redirect_to invitation_requests_path
			return
		end
		
		@invitation_request = InvitationRequest.find_by_id id
		if !@invitation_request
			flash[:error] = "Invitation request #{id} was not found"
			redirect_to invitation_requests_path
			return
		end

		if @invitation_request.status != InvitationRequest::Statuses::CREATED
			error = "Cannot decline invitation request #{@invitation_request.id} for #{ERB::Util.h @invitation_request.person.name}"
			error += "<br />"
			error += "<br />"
			error += 'The status must "accepted" for the invitation request to be allowed to be declined or accepted'
			flash[:error] = error
			redirect_to invitation_requests_path
		end
	end
	
end
